﻿using System;

using BrightSword.Feber.Samples;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Tests.BrightSword.Feber.TestClasses;

namespace Tests.BrightSword.Feber
{
    [TestClass]
    public class FastMapperTests
    {
        [TestMethod]
        public void TestStaticToStatic()
        {
            var source = new ClassA
                         {
                             Integer = 42,
                             DateTime = new DateTime(2009,
                                                     2,
                                                     7),
                             String = "Black Saturday"
                         };

            var destination = new ClassA().MapStaticToStatic(source);

            Assert.AreEqual(source.Integer,
                            destination.Integer);
            Assert.AreEqual(source.String,
                            destination.String);
            Assert.AreEqual(source.DateTime,
                            destination.DateTime);
        }

        [TestMethod]
        public void TestStaticToStatic_SpecificTypes()
        {
            var source = new ClassA
                         {
                             Integer = 42,
                             DateTime = new DateTime(2009,
                                                     2,
                                                     7),
                             String = "Black Saturday"
                         };

            var destination = new ClassB();

            FastMapper<ClassA>.MapStaticToStatic(source,
                                                 destination);

            Assert.AreEqual(source.Integer,
                            destination.Integer);
            Assert.AreEqual(source.String,
                            destination.String);
            Assert.AreEqual(source.DateTime,
                            destination.DateTime);
            Assert.AreEqual(0.0M,
                            destination.Amount);
        }

        [TestMethod]
        public void TestStaticToDynamic()
        {
            var source = new ClassA
                         {
                             Integer = 42,
                             DateTime = new DateTime(2009,
                                                     2,
                                                     7),
                             String = "Black Saturday"
                         };

            dynamic destination = new ClassA();

            destination = FastMapper.MapStaticToDynamic(destination,
                                                        source);

            Assert.AreEqual(source.Integer,
                            destination.Integer);
            Assert.AreEqual(source.String,
                            destination.String);
            Assert.AreEqual(source.DateTime,
                            destination.DateTime);
        }

        [TestMethod]
        public void TestStaticToDynamicBackingFields()
        {
            var source = new ClassA
                         {
                             Integer = 42,
                             DateTime = new DateTime(2009,
                                                     2,
                                                     7),
                             String = "Black Saturday"
                         };

            dynamic destination = new ClassA_With_BackingFields();

            destination = FastMapper.MapToBackingFields(destination,
                                                        source);

            Assert.AreEqual(source.Integer,
                            destination.Integer);
            Assert.AreEqual(source.String,
                            destination.String);
            Assert.AreEqual(source.DateTime,
                            destination.DateTime);
        }

        [TestMethod]
        public void TestDynamicToStatic()
        {
            dynamic source = new ClassA
                             {
                                 Integer = 42,
                                 DateTime = new DateTime(2009,
                                                         2,
                                                         7),
                                 String = "Black Saturday"
                             };

            var destination = new ClassA();

            destination = FastMapper.MapDynamicToStatic<ClassA>(destination,
                                                                source);

            Assert.AreEqual(source.Integer,
                            destination.Integer);
            Assert.AreEqual(source.String,
                            destination.String);
            Assert.AreEqual(source.DateTime,
                            destination.DateTime);
        }

        [TestMethod]
        public void TestDynamicToDynamic()
        {
            dynamic source = new ClassA
                             {
                                 Integer = 42,
                                 DateTime = new DateTime(2009,
                                                         2,
                                                         7),
                                 String = "Black Saturday"
                             };

            dynamic destination = new ClassA();

            destination = FastMapper.MapDynamicToDynamic<ClassA>(destination,
                                                                 source);

            Assert.AreEqual(source.Integer,
                            destination.Integer);
            Assert.AreEqual(source.String,
                            destination.String);
            Assert.AreEqual(source.DateTime,
                            destination.DateTime);
        }
    }
}